import { requestClient } from '#/api/request'

import { downloadFileFromBlobPart } from '@vben/utils'

/**
 * 获取物料库存详情列表
 */
export async function getMaterialStockDetailList(params: any) {
  return requestClient.get('/admin/MaterialStockDetail/index', params)
}

/**
 * 获取库存记录列表
 */
export async function getStockRecordList(params: any) {
  return requestClient.get('/admin/MaterialStockDetail/stockRecord', params)
}

/**
 * 获取库存明细列表
 */
export async function getMaterialActionLogList(params: any) {
  return requestClient.get('/admin/MaterialActionLog/index', params)
}

/**
 * 导出物料库存详情
 */
export async function exportExpiredData(params: any) {
  const res = await requestClient.get('/admin/materialStockDetail/exportMaterialStock', params, {
    responseType: 'blob', // 设置响应类型为 blob
    responseReturn: 'raw', // 返回原始响应而不是解析后的数据
  })

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '生产面辅料逾期情况.xlsx',
  })
}
